<?php
# 1 接收数据
$name = 'xiaotian1';
$platform ='wangyi';
# 2 连接认证
$conn = @mysqli_connect('localhost','root','root') or die(iconv('gbk','utf-8',mysqli_connect_error()));
# 3 设置字符集
mysqli_set_charset($conn,'utf8') or die(mysqli_error($conn));
# 4 选择数据库
mysqli_select_db($conn,'news') or die(mysqli_error($conn));
# 5 组织sql指令
$sql = "insert into author values(null,'$name','$platform')";
// var_dump($sql);
# 确定是否返回自增长id
$auto_id = true; 
# 6 执行sql语句写入到数据库
$res = mysqli_query($conn,$sql) or die(mysqli_error($conn));
# 7 返回结果

if(isset($auto_id)){
	echo mysqli_insert_id($conn); # 增长id
}else{
	echo mysqli_affected_rows($conn);# 受影响的行数
}
# 关闭链接

mysqli_close($conn);

